/* Copyright (C) 
 * 2010 - Insighten  taco [tacoee@gmail.com]
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 */
#ifndef	_FIFO_H
#define _FIFO_H
#include <pthread.h>
struct fifo {
	unsigned char *data;
	unsigned int size;
	unsigned int in;
	unsigned int out;
	int lock_flag;
	pthread_mutex_t mutex;
};

static inline void fifo_reset(struct fifo *thiz)
{
	thiz->in = thiz->out = 0;
}

static inline unsigned int fifo_len(struct fifo *thiz)
{
	return thiz->in - thiz->out;
}

struct fifo *fifo_init(int size, int lock_flag);
int fifo_free(struct fifo *thiz);
unsigned int fifo_write(struct fifo *thiz, 
		unsigned char *data, unsigned int len);
unsigned int fifo_read(struct fifo *thiz,
		unsigned char *data, unsigned int len);

#endif /*_FIFO_H*/
